<?php
include_once("config.php");
$minnum = $_POST['minnum'];
$maxnum = $_POST['maxnum'];
$action = $_POST['action'];
session_start();
if($action==0){
    $result=mysql_query("SELECT * FROM form_pbl_pices where id BETWEEN ".$minnum." and ".$maxnum.";");
    while($row=mysql_fetch_array($result))
    {
    	$array[]=$row;
    }
    $json_string=json_encode($array);

    $_SESSION['max']=$maxnum;

    echo $json_string;
    mysql_close($con);
}elseif($action==1){
    $anum=((int)$maxnum+(int)$_SESSION['max']);
    $result=mysql_query("SELECT * FROM form_pbl_pices where id BETWEEN ".(((int)$_SESSION['max'])+1)." and ".$anum.";");
    while($row=mysql_fetch_array($result))
    {
    	$array[]=$row;
    }
    $json_string=json_encode($array);
    $_SESSION['max']=$anum;
    echo $json_string;
    mysql_close($con);
}
?>
